﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;
using System.ComponentModel;
using XCI.Core;
using XCI.Helper;

namespace XCI.Windows
{
    /// <summary>
    /// Form基类
    /// </summary>
    public partial class BaseForm : DevExpress.XtraEditors.XtraForm
    {
        private LoadingMask _loading;
        private MutexStatus _mutex;
        private OnceAction _onceAction;

        public BaseForm()
        {
            InitializeComponent();
            if (WinFormHelper.IsDesignMode()) WinFormHelper.InitDesignFont();
        }

        /// <summary>
        /// 是否设计模式
        /// </summary>
        [Browsable(false)]
        protected new bool DesignMode => WinFormHelper.IsDesignMode();

        /// <summary>
        /// Loading面板
        /// </summary>
        [Browsable(false)] 
        protected LoadingMask Loading => _loading ?? (_loading = new LoadingMask(this));

        /// <summary>
        /// 互斥状态
        /// </summary>
        [Browsable(false)]
        protected MutexStatus Mutex => _mutex ?? (_mutex = new MutexStatus());

        /// <summary>
        /// 一次性执行函数
        /// </summary>
        [Browsable(false)]
        protected OnceAction OnceAction => _onceAction ?? (_onceAction = new OnceAction());

        /// <summary>
        /// Form参数
        /// </summary>
        [Browsable(false)]
        public SMap Args { get; set; }

        protected override void OnLoad(EventArgs e)
        {
            if (WinFormHelper.IsDesignMode()) WinFormHelper.InitDesignFont();
            base.OnLoad(e);
            if (WinFormHelper.IsDesignMode())
            {
                WinFormHelper.InitDesignFont();
                RepositoryItemComboBoxEditx.RegisterComboBoxEditx();
                RepositoryItemRadioGroupx.RegisterRadioGroupx();
                RepositoryItemImageComboBoxEditx.RegisterImageComboBoxEditx();
                RepositoryItemPopupGridControlEdit.RegisterPopupGridControlEdit();
                RepositoryItemPopupGridControlPagingEdit.RegisterPopupGridControlPagingEdit();

                RepositoryItemStatusComboBoxEdit.RegisterStatusComboBoxEdit();
                RepositoryItemStatusTextEdit.RegisterStatusTextEdit();
                RepositoryItemDicComboBoxEdit.RegisterDicComboBoxEdit();
                RepositoryItemDicRadioGroupx.RegisterDicRadioGroupx();
                RepositoryItemCheckedComboBoxEditx.RegisterCheckedComboBoxEditx();
                RepositoryItemDicCheckedComboBoxEdit.RegisterDicCheckedComboBoxEdit();
            }
        }

        /// <summary>
        /// 设置窗口的DialogResult的值为OK
        /// </summary>
        protected void DialogOk()
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        /// <summary>
        /// 设置窗口的DialogResult的值为Cancel
        /// </summary>
        protected void DialogCancel()
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

        /// <summary>
        /// 设置窗口的DialogResult的值为Ignore
        /// </summary>
        protected void DialogIgnore()
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Ignore;
        }
    }
}